#!/usr/bin/env bash

#get this script real directory
SOURCE="$0"
while [ -h "$SOURCE"  ]; do # resolve $SOURCE until the file is no longer a symlink
    this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"
    SOURCE="$(readlink "$SOURCE")"
    # if $SOURCE was a relative symlink, 
    #we need to resolve it relative to the path 
    #where the symlink file was located
    [[ $SOURCE != /*  ]] && SOURCE="$this_script_dir/$SOURCE"
done
this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"

log_level=${log_level:=info}
assist_dir=${assist_dir:=$this_script_dir/assist}
source $assist_dir/global.sh

clear_all()
{
    local trash_dir=$HOME/.Trash
    if [ -d $trash_dir ]; then
        #cd $trash_dir && /bin/rm -rf 20*

        cd $trash_dir
        echo "start to clear $trash_dir ..."

        local total=$(ls | wc -l)
        local index=0

        if [ $total -eq 0 ] ; then 
            vlogi "there is nothing in trash directory, trash is clean."
            return 0
        fi

        #progress configure
        progress_label="Delete trash"
        ls -tr1 |
            while read line
            do
                let index++
                local msg=`printf "[%02d/%d] /bin/rm -rf \"%s\"\n" $index $total "$line"`
                printf_progress $index $total "$msg"
                sleep 1 
                [ $(pwd) == "$trash_dir" ] && /bin/rm -rf "$line"
            done
    fi
    printf "\n"
}

main()
{
    clear_all
}

main || exit $? && exit 0
